<template>
    <div>
       <van-uploader :after-read="afterRead"></van-uploader>
       <van-button @click="pay(1,2)">支付</van-button>
    </div>
</template>

<script>
    import Vue from 'vue';
    import { Uploader } from 'vant';
    import { ApiService } from "../../../axios/apiService";

    Vue.use(Uploader);

    export default {
        methods: {
            async afterRead(file) {
                console.log("this.afterRead()")
                //初试化
                let OSS = require('ali-oss');
                // var testFile = new File();
                // console.log(testFile);

                let client = new OSS({
                    region: 'oss-cn-chengdu',
                    accessKeyId:'LTAI5tKbKKZo33r8EpDqgGWH',
                    accessKeySecret:'wPzuRowwhcB7brUAwDfTcEIo8hAnBI',
                    bucket: 'jingzai-pethome',
                });
                //此时可以自行将文件上传至服务器
                try {
                    // 填写Object完整路径和本地文件的完整路径。Object完整路径中不能包含Bucket名称。
                    // 如果未指定本地路径，则默认从示例程序所属项目对应本地路径中上传文件。
                    console.log(new Date().getTime())
                    var ti = new Date().getTime()
                    let result = await client.put('/img/'+ti+'.jpg',file.file)
                    console.log(result)
                } catch (e) {
                    console.log(e);
                }
            },
            //支付宝
            pay(order,index) {
                console
                const api = new ApiService("/pay")
                api.getViewList().then(res => {
                    console.log("res"+res);
                    const div = document.createElement('div')
                    div.innerHTML = res.data
                    document.body.appendChild(div)
                    document.forms[0].submit()
                    //调用状态更新
                    console.log(order,index)
                    //this.updateType(order,index)
                })
            }

        },
    };
</script>